#! /bin/sh

# Write profile to DSP DAC and play a test tone

OUT=/dev/tty1

case "$1" in
    start)
	echo "Testing RTC"  > $OUT
        modprobe i2c-bcm2835
        modprobe i2c-dev
        modprobe rtc-ds1307
        echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new_device
        hwclock -s
        if [ $? != 0 ]; then
          echo "RTC clock module not responding, aborting"
          exit 1
        fi
        hwclock -r
        if [ $? != 0 ]; then
          echo "RTC clock module not responding, aborting"
          exit 1
        fi

	echo "Testing LED (if available)" > $OUT
        gpio mode 4 out
        gpio write 4 1

	echo "Playing test tone" > $OUT
	play -n synth 30 sine 1000 > $OUT
	echo "Done" > $OUT
	;;
    stop)
	;;
    restart)
	$0 stop
	$0 start
	;;
    *)
	echo "Usage: $0 {start|stop|restart}"
	exit 1
	;;
esac

